<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('隐患表单')" />
	<link rel="stylesheet" href="/libs/mui/css/mui.min.css">
	<link rel="stylesheet" type="text/css" href="/libs/mui/css/app.css" />
	<link rel="stylesheet" type="text/css" href="/libs/mui/css/mui.picker.min.css" />
	<link rel="stylesheet" type="text/css" href="/common/css/form.css">
	<link  rel="stylesheet" type="text/css"  href="/libs/webuploader/webuploader.css"/>
</head>
<body class="up_body">
<div class="mui-content up_form_content">
	<!--表单start-->
	<form class="mui-input-group up_group" id="form">
		<div class="up_gray"></div>
		<div class="up_gray"></div>
		<div class="up_row">
			<label><font>*</font>检查单位</label>
			<input type="hidden" value="" name="CreateOrganizationID">
			<input type="text" class="icon_more" onclick="selectDeptTree(this)" name="ignore0" bind-name="CreateOrganizationID" placeholder="请选择" id="CreateOrganizationID"  required>
			<div class="clear_both"></div>
		</div>
		<div class="up_row">
			<label><font>*</font>检查人：</label>
			<input type="hidden" value="" name="DiscoverUserIDs">
			<input type="text" class="icon_more" onclick="selectUserTree(this)" name="ignore1" bind-name="DiscoverUserIDs" placeholder="请选择" id="DiscoverUserIDs"  required>
			<div class="clear_both"></div>
		</div>
		<div class="up_gray"></div>
		<div class="up_row">
			<label><font>*</font>检查时间</label>
			<input type="text" class="date-select icon_more" placeholder="请选择" name="FindDate" required>
			<div class="clear_both"></div>
		</div>
		<div class="up_row record-select" th:data="${@dict.getTypeByJson('HIHiddenDangerTypes')}">
			<label><font>*</font>隐患类型</label>
			<input type="text" class="record-select-data icon_more" name="ignore3" placeholder="请选择" required>
			<input type="hidden" class="record-select-id" name="HIHiddenDangerTypeID">
			<icon class="icon_more fright"></icon>
			<div class="clear_both"></div>
		</div>
		<div class="up_row record-select" th:data="${@dict.getTypeByJson('HIHiddenDangerLevels')}">
			<label><font>*</font>隐患等级</label>
			<input type="text" class="record-select-data icon_more" name="ignore4" placeholder="请选择" required>
			<input type="hidden" class="record-select-id" name="HIHiddenDangerLevelID">
			<icon class="icon_more fright"></icon>
			<div class="clear_both"></div>
		</div>
		<div class="up_row">
			<label><font>*</font>整改期限</label>
			<input type="text" class="date-select icon_more" placeholder="请选择" name="DeadLine" required>
			<icon class="icon_more fright"></icon>
			<div class="clear_both"></div>
		</div>
		<div class="up_row">
			<label><font>*</font>责任单位</label>
			<input type="hidden" name="ResOrganizationID" />
			<input type="text" class="icon_more" onclick="selectDeptTree(this)" name="ignore5" bind-name="ResOrganizationID" placeholder="请选择" id="treeName"  required>
			<icon class="icon_more fright"></icon>
			<div class="clear_both"></div>
		</div>
		<div class="up_row">
			<label><font>*</font>整改责任人</label>
			<input type="hidden" name="ResUserID" />
			<input type="text" class="icon_more" onclick="selectUserTree(this)" name="ignore6" bind-name="ResUserID" placeholder="请选择" id="ResUserName"  required>
			<icon class="icon_more fright"></icon>
			<div class="clear_both"></div>
		</div>
		<div class="up_row" th:if="${isLeader == false}">
			<label><font>*</font>复查人</label>
			<input type="hidden" name="Status" th:value="2">
			<input type="hidden" name="ReviewUserID"/>
			<input type="text" class="icon_more" onclick="selectUserTree(this)" name="ignore7" bind-name="ReviewUserID" placeholder="请选择" id="ReviewUserName"  required>
			<div class="clear_both"></div>
		</div>
		<div class="up_row"  th:if="${isLeader == true}">
			<label><font>*</font>审核人</label>
			<input type="hidden" name="Status" th:value="1">
			<input type="hidden" name="FirstUserID"/>
			<input type="text" class="icon_more" onclick="selectUserTree(this)" name="ignore8" bind-name="FirstUserID" placeholder="请选择" id="FirstUserName"  required>
			<div class="clear_both"></div>
		</div>
		<div id="filePicker" class="up_file_img"></div>
		<div class="mui-input-row up_row up_file_list up_fileimg_list">
			<input type="hidden" id="imageIds" name="CreateAttachment"/>
			<label><font></font>隐患附件</label>
			<div class="clear_both"></div>
			<div class="up_fileimg_right">
				<div id="preview"></div>
				<div class="clear_both"></div>
				<div></div>
			</div>
			<div class="clear_both"></div>
		</div>
		<div class="up_gray"></div>
		<div class="up_row up_btextarea">
			<label><font>*</font>隐患内容</label>
			<textarea rows="5" placeholder="请输入" name="HDName" required></textarea>
		</div>
		<div class="up_row up_btextarea">
			<label><font>*</font>隐患地点</label>
			<textarea rows="5" placeholder="请输入" name="HDPlace" required></textarea>
		</div>
		<div class="up_row up_btextarea">
			<label><font>*</font>整改要求</label>
			<textarea rows="5" placeholder="请输入" name="RectificationRequest" required></textarea>
		</div>
		<div class="up_gray"></div>
		<!--表单end-->
		<div class="up_button">
			<input type="button" id="submit" class="up_button_left" value="提交" />
			<input type="button" class="up_button_right" value="保存" /></div>
		<div class="clear_both"></div>
	</form>
</div>
</body>
<th:block th:include="include :: footer" />
<script src="/libs/mui/js/mui.min.js"></script>
<script src="/libs/mui/js/mui.picker.min.js"></script>
<script src="/libs/webuploader/webuploader.nolog.js"></script>
<script src="/common/js/form.js"></script>
<script>
	//回显内容
	$("#CreateOrganizationID").val($.userOperate.deptName());
	$("#DiscoverUserIDs").val($.userOperate.userName());
	$("[name=CreateOrganizationID]").val($.userOperate.deptId());
	$("[name=DiscoverUserIDs]").val($.userOperate.userId());

    /**
	 * 数据校验
     */
    $("#form").validate({
        focusCleanup: true
    });

    document.getElementsByTagName("input").oninput = function () {
		console.log(111);
    };

	/*$(document).on("input","input propertychange",function () {
		console.log("内容改变");
		$.validate.form();
    });*/

	//提交
	$(".up_button_left").click(function(){
	    console.log($.common.serializeNotNull()+"&entityName=HIHiddenDanger&opName=Apply&userId="+$.userOperate.userId());
	    var data = $("form").serialize()+"&entityName=HIHiddenDanger&opName=Apply&userId="+$.userOperate.userId();
	    console.log(data);
	    if($.validate.form()){
            $.ajax({
                url:ctx+"/public/Save",
                type:"post",
                data:data,
                dataType:"json",
                success:function (obj) {
                    if(obj.statusCode==0){
                        location.href = "/hidden/home?openId="+$.userOperate.openId();
                    }else{
                        alert(obj.statusMsg);
                    }
                }
            })
		}
	});
    //保存*
    $(".up_button_right").click(function(){
        $("[name=Status]").val("0");
        if ($.validate.form()) {
            $.ajax({
                async:false,
                url:ctx+"/public/Save",
                type:"post",
                data:$("form").serialize()+"&entityName=HIHiddenDanger&opName=Edit&userId="+$.userOperate.userId(),
                dataType:"json",
                success:function (obj) {
                    if(obj.statusCode==0){
                        location.href = "/hidden/home?openId="+$.userOperate.openId();
                    }else{
                        alert(obj.statusMsg);
                    }
                }
            })
        }
    });

    // 初始化Web Uploader
    var uploader = WebUploader.create({
        // 选完文件后，是否自动上传。
        auto: true,

        // 文件接收服务端。
        server: ctx + '/public/UpoladFiles',

        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#filePicker',

        // 只允许选择图片文件。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });
    //初始化图片上传 事件
    uploaderInit(uploader);
    //删除图片
    $(document).on("click",".file_close",function(){
        var fileDiv = $(this).parent();
        var fileId = fileDiv.attr("id");
        var imageIds = $("#imageIds").val();
        $("#imageIds").val(imagesIdsReplace(imageIds,fileDiv));
        fileDiv.remove();
        uploader.removeFile(fileId);
    });
</script>
</html>
